
<h1><span class="yiyi-st" id="yiyi-13">numpy.ma.masked_where</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.masked_where.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.masked_where.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.ma.masked_where"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">numpy.ma.</code><code class="descname">masked_where</code><span class="sig-paren">(</span><em>condition</em>, <em>a</em>, <em>copy=True</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/ma/core.py#L1805-L1919"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-15">屏蔽满足条件的数组。</span></p>
<p><span class="yiyi-st" id="yiyi-16">将<em class="xref py py-obj">a  t&gt;返回为屏蔽的数组，其中<em class="xref py py-obj">条件</em>为True。</em></span><span class="yiyi-st" id="yiyi-17">任何屏蔽的<em class="xref py py-obj">a</em>或<em class="xref py py-obj">条件</em>也会在输出中被屏蔽。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-18">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-19"><strong>condition</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-20">屏蔽条件。</span><span class="yiyi-st" id="yiyi-21">当<em class="xref py py-obj">条件</em>测试浮点值的相等性时，请考虑使用<code class="docutils literal"><span class="pre">masked_values</span></code>。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-22"><strong>a</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-23">数组掩码。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-24"><strong>copy</strong>：bool</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-25">如果为True（默认值），则在结果中复制<em class="xref py py-obj">a</em>。</span><span class="yiyi-st" id="yiyi-26">如果False修改<em class="xref py py-obj">a</em>并返回视图。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-27">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-28"><strong>result</strong>：MaskedArray</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-29">屏蔽<em class="xref py py-obj">a</em>的结果，其中<em class="xref py py-obj">条件</em>为True。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-30">也可以看看</span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-31"><a class="reference internal" href="numpy.ma.masked_values.html#numpy.ma.masked_values" title="numpy.ma.masked_values"><code class="xref py py-obj docutils literal"><span class="pre">masked_values</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-32">使用浮点平等的掩码。</span></dd>
<dt><span class="yiyi-st" id="yiyi-33"><a class="reference internal" href="numpy.ma.masked_equal.html#numpy.ma.masked_equal" title="numpy.ma.masked_equal"><code class="xref py py-obj docutils literal"><span class="pre">masked_equal</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-34">掩码等于给定值。</span></dd>
<dt><span class="yiyi-st" id="yiyi-35"><a class="reference internal" href="numpy.ma.masked_not_equal.html#numpy.ma.masked_not_equal" title="numpy.ma.masked_not_equal"><code class="xref py py-obj docutils literal"><span class="pre">masked_not_equal</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-36">其中<em class="xref py py-obj">不</em>等于给定值的掩码。</span></dd>
<dt><span class="yiyi-st" id="yiyi-37"><a class="reference internal" href="numpy.ma.masked_less_equal.html#numpy.ma.masked_less_equal" title="numpy.ma.masked_less_equal"><code class="xref py py-obj docutils literal"><span class="pre">masked_less_equal</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-38">掩码小于或等于给定值。</span></dd>
<dt><span class="yiyi-st" id="yiyi-39"><a class="reference internal" href="numpy.ma.masked_greater_equal.html#numpy.ma.masked_greater_equal" title="numpy.ma.masked_greater_equal"><code class="xref py py-obj docutils literal"><span class="pre">masked_greater_equal</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-40">掩码大于或等于给定值。</span></dd>
<dt><span class="yiyi-st" id="yiyi-41"><a class="reference internal" href="numpy.ma.masked_less.html#numpy.ma.masked_less" title="numpy.ma.masked_less"><code class="xref py py-obj docutils literal"><span class="pre">masked_less</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-42">掩码小于给定值。</span></dd>
<dt><span class="yiyi-st" id="yiyi-43"><a class="reference internal" href="numpy.ma.masked_greater.html#numpy.ma.masked_greater" title="numpy.ma.masked_greater"><code class="xref py py-obj docutils literal"><span class="pre">masked_greater</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-44">掩码大于给定值。</span></dd>
<dt><span class="yiyi-st" id="yiyi-45"><a class="reference internal" href="numpy.ma.masked_inside.html#numpy.ma.masked_inside" title="numpy.ma.masked_inside"><code class="xref py py-obj docutils literal"><span class="pre">masked_inside</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-46">给定间隔内的掩码。</span></dd>
<dt><span class="yiyi-st" id="yiyi-47"><a class="reference internal" href="numpy.ma.masked_outside.html#numpy.ma.masked_outside" title="numpy.ma.masked_outside"><code class="xref py py-obj docutils literal"><span class="pre">masked_outside</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-48">在给定间隔之外屏蔽。</span></dd>
<dt><span class="yiyi-st" id="yiyi-49"><a class="reference internal" href="numpy.ma.masked_invalid.html#numpy.ma.masked_invalid" title="numpy.ma.masked_invalid"><code class="xref py py-obj docutils literal"><span class="pre">masked_invalid</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-50">屏蔽无效值（NaN或infs）。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-51">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy.ma</span> <span class="k">as</span> <span class="nn">ma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span>
<span class="go">array([0, 1, 2, 3])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">masked_where</span><span class="p">(</span><span class="n">a</span> <span class="o">&lt;=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
<span class="go">masked_array(data = [-- -- -- 3],</span>
<span class="go">      mask = [ True  True  True False],</span>
<span class="go">      fill_value=999999)</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-52">条件为<em class="xref py py-obj">a</em>的掩码数组<em class="xref py py-obj">b</em>。</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&apos;a&apos;</span><span class="p">,</span> <span class="s1">&apos;b&apos;</span><span class="p">,</span> <span class="s1">&apos;c&apos;</span><span class="p">,</span> <span class="s1">&apos;d&apos;</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">masked_where</span><span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="mi">2</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="go">masked_array(data = [a b -- d],</span>
<span class="go">      mask = [False False  True False],</span>
<span class="go">      fill_value=N/A)</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-53"><a class="reference internal" href="numpy.ma.copy.html#numpy.ma.copy" title="numpy.ma.copy"><code class="xref py py-obj docutils literal"><span class="pre">copy</span></code></a>参数的效果。</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">masked_where</span><span class="p">(</span><span class="n">a</span> <span class="o">&lt;=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span>
<span class="go">masked_array(data = [-- -- -- 3],</span>
<span class="go">      mask = [ True  True  True False],</span>
<span class="go">      fill_value=999999)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">99</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span>
<span class="go">masked_array(data = [99 -- -- 3],</span>
<span class="go">      mask = [False  True  True False],</span>
<span class="go">      fill_value=999999)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span>
<span class="go">array([0, 1, 2, 3])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">masked_where</span><span class="p">(</span><span class="n">a</span> <span class="o">&lt;=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">99</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span>
<span class="go">masked_array(data = [99 -- -- 3],</span>
<span class="go">      mask = [False  True  True False],</span>
<span class="go">      fill_value=999999)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span>
<span class="go">array([99,  1,  2,  3])</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-54">当<em class="xref py py-obj">条件</em>或<em class="xref py py-obj">a</em>包含屏蔽值时。</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">masked_where</span><span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="mi">2</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span>
<span class="go">masked_array(data = [0 1 -- 3],</span>
<span class="go">      mask = [False False  True False],</span>
<span class="go">      fill_value=999999)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">ma</span><span class="o">.</span><span class="n">masked_where</span><span class="p">(</span><span class="n">b</span> <span class="o">==</span> <span class="mi">0</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span>
<span class="go">masked_array(data = [-- 1 2 3],</span>
<span class="go">      mask = [ True False False False],</span>
<span class="go">      fill_value=999999)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ma</span><span class="o">.</span><span class="n">masked_where</span><span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="mi">3</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="go">masked_array(data = [-- 1 -- --],</span>
<span class="go">      mask = [ True False  True  True],</span>
<span class="go">      fill_value=999999)</span>
</pre></div>
</div>
</dd></dl>
